package com.jjw.springbootcvs.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jjw.springbootcvs.mapper.StorageRecordMapper;
import com.jjw.springbootcvs.pojo.dto.StorageRecordAndSupplierDTO;
import com.jjw.springbootcvs.pojo.entity.StorageRecord;
import com.jjw.springbootcvs.pojo.vo.PageStorageRecordListVO;
import com.jjw.springbootcvs.service.StorageRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author xiaojuan
 * @Date 2024/11/2
 * @Description
 */
@Service
public class StorageRecordServiceImpl implements StorageRecordService {

    @Autowired
    private StorageRecordMapper storageRecordMapper;

    @Override
    public PageInfo<PageStorageRecordListVO> getAllStorageRecordList(StorageRecordAndSupplierDTO storageRecordAndSupplierDTO) {
        PageHelper.startPage(storageRecordAndSupplierDTO.getPageIndex()==null?1:storageRecordAndSupplierDTO.getPageIndex(),10);
        List<PageStorageRecordListVO> storageRecordList = storageRecordMapper.getAllStorageRecordList(storageRecordAndSupplierDTO);
        return new PageInfo<>(storageRecordList);
    }

    @Override
    public void add(StorageRecord storageRecord) {
        storageRecord.setCreatedTime(LocalDateTime.now());
        storageRecord.setUpdatedTime(LocalDateTime.now());
        storageRecordMapper.insertSelective(storageRecord);
    }

    @Override
    public StorageRecord getStorageRecordById(Long id) {
        return storageRecordMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(StorageRecord storageRecord) {
        storageRecordMapper.updateByPrimaryKeySelective(storageRecord);
    }

    @Override
    public void delete(Long id) {
        storageRecordMapper.deleteByPrimaryKey(id);
    }
}
